package com.cuit.dashboard.system.controller;


import com.cuit.dashboard.common.util.Result;
import com.cuit.dashboard.system.service.SysLoginLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @program: zuke
 * @description: 系统登录日志
 * @author: KamTang
 * @create: 2022-06-11 15:52
 **/
@RestController
@RequestMapping("/sys/loginLog")
public class SysLoginLogController {

    @Autowired
    private SysLoginLogService loginLogService;

    @GetMapping("/list")
    public Result list(@RequestParam Map<String, Object> params) {
        return Result.ok().put("loginLogPage", loginLogService.findLoginLogList(params));
    }

    /**
     * 登入报表
     *
     * @return
     */
    @GetMapping("/loginReport/{username}")
    public Result loginReport(@PathVariable("username") String username) {
        List<Map<String, Object>> mapList = loginLogService.loginReport(username);
        Map<String, Object> map = new HashMap<>();
        List<Map<String, Object>> meList = loginLogService.loginReport(null);
        map.put("me", meList);
        map.put("all", mapList);
        return Result.ok().put("loginReport", map);
    }

    /**
     * 删除登录日志
     *
     * @param ids
     * @return
     */
    @PostMapping("/delete")
    public Result deleteReport(@RequestBody Long[] ids) {
        loginLogService.deleteBatch(ids);
        return Result.ok();
    }

    //@GetMapping("/getWeeklyAdminLoginAndUserRegData")
    //public Map<String, List<?>> getWeeklyAdminLoginAndUserRegData() {
    //    return loginLogService.getWeeklyAdminLoginAndUserRegData();
    //}

}
